package com.jp.java8;

public class NullPointException {

    public static void main(String[] args) {
       String insuranceName =  getInsuranceName(new Person());
       //String insuranceName =  getInsuranceNameByDeepDoubts(new Person());
       System.out.println(insuranceName);
    }

    private static String getInsuranceNameByDeepDoubts(Person person){
        if(null != person){
            Car car = person.getCar();
            if(null!=car){
                Insurance insurance = car.getInsurance();
                if(null != insurance){
                    return insurance.getName();
                }
            }
        }
        return "UNKOWN";
    }


    private static String getInsuranceNameByDefault(Person person){
        String result = "UNKOWN";
        if(null != person){
            Car car = person.getCar();
            if(null!=car){
                Insurance insurance = car.getInsurance();
                if(null != insurance){
                    return insurance.getName();
                }
            }
        }
        return result;
    }

    private static String getInsuranceName(Person person) {
        return person.getCar().getInsurance().getName();
    }
}
